﻿using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Text;
using System.Net;
using Planer.UI;

namespace Planer.Logic
{
    class MailSender
    {

        public static void SendMail(string text, string subject, string toEmail, string toName)
        {
            Program.LoginForm.Cursor = System.Windows.Forms.Cursors.WaitCursor;

            MailAddress fromAddress = new MailAddress("budget.planer@gmail.com", "Восстановление пароля");
            MailAddress toAddress = new MailAddress(toEmail, toName);
            string fromPassword = "1862spy1ro";
            string body = text;

            try
            {
                SmtpClient smtp = new SmtpClient
                           {
                               Host = "smtp.gmail.com",
                               Port = 587,
                               EnableSsl = true,
                               DeliveryMethod = SmtpDeliveryMethod.Network,
                               UseDefaultCredentials = false,
                               Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
                           };
                using (MailMessage message = new MailMessage(fromAddress, toAddress)
                                     {
                                         Subject = subject,
                                         Body = body
                                     })
                {
                    smtp.Send(message);
                }
            }
            catch (Exception ex)
            {
                MessageBoxUtils.ShowErrorBox(ex.Message);
            }

            Program.LoginForm.Cursor = System.Windows.Forms.Cursors.Default;
        }
    }
}
